package nthu.web.view;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import nthu.web.model.domain.User;
import nthu.web.service.json.JsonService;


@SuppressWarnings("serial")
public class CurrentUserView extends ResourceView<User> {

	@Override
	public void doPost(HttpServletRequest request, HttpServletResponse response) 
													throws ServletException, IOException {
		
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();

		out.println("系統創建成功!<br/>");
        
		out.close();
    	
	}
	
	@Override
	public void doGet(HttpServletRequest request, HttpServletResponse response) 
													throws ServletException, IOException {
		@SuppressWarnings("unchecked")
		ArrayList<User> currentlist = (ArrayList<User>) getModel(request);
		/*
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		
		for(int i = 0; i < currentlist.size(); i++) 
			out.println(currentlist.get(i).toString()+"<br/>");
        
		out.close();
    	*/
		
		response.setContentType("application/json");
		response.setHeader("Cache-Control", "no-cache"); // make sure no intermediate node caches the result
		response.setCharacterEncoding("UTF-8");
		response.getWriter().print(JsonService.serialize(currentlist));
		
		
		
		
	}
	
	
    
}
